using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class Itm_CodeMapMap : EntityTypeConfiguration<Itm_CodeMap>
    {
        public Itm_CodeMapMap()
        {
            // Primary Key
            this.HasKey(t => new { t.Itm_CM_ID, t.Itm_CM_ITEM, t.Itm_CM_AltItem });

            // Properties
            this.Property(t => t.Itm_CM_ID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(t => t.Itm_CM_Codetype)
                .HasMaxLength(20);

            this.Property(t => t.Itm_CM_ITEM)
                .IsRequired()
                .HasMaxLength(10);

            this.Property(t => t.Itm_CM_AltItem)
                .IsRequired()
                .HasMaxLength(10);

            this.Property(t => t.Itm_CM_Teeth)
                .HasMaxLength(100);

            this.Property(t => t.Itm_CM_CaseItems)
                .HasMaxLength(100);

            // Table & Column Mappings
            this.ToTable("Itm_CodeMap");
            this.Property(t => t.Itm_CM_ID).HasColumnName("Itm_CM_ID");
            this.Property(t => t.Itm_CM_Codetype).HasColumnName("Itm_CM_Codetype");
            this.Property(t => t.Itm_CM_ITEM).HasColumnName("Itm_CM_ITEM");
            this.Property(t => t.Itm_CM_AltItem).HasColumnName("Itm_CM_AltItem");
            this.Property(t => t.Itm_CM_FromTooth_).HasColumnName("Itm_CM_FromTooth#");
            this.Property(t => t.Itm_CM_ToTooth_).HasColumnName("Itm_CM_ToTooth#");
            this.Property(t => t.Itm_CM_Teeth).HasColumnName("Itm_CM_Teeth");
            this.Property(t => t.Itm_CM_CaseItems).HasColumnName("Itm_CM_CaseItems");
            this.Property(t => t.Itm_CM_ToothMap).HasColumnName("Itm_CM_ToothMap");
            this.Property(t => t.Itm_CM_CaseMap).HasColumnName("Itm_CM_CaseMap");

            // Relationships
            this.HasRequired(t => t.Item)
                .WithMany(t => t.Itm_CodeMap)
                .HasForeignKey(d => d.Itm_CM_AltItem);
            this.HasRequired(t => t.Item1)
                .WithMany(t => t.Itm_CodeMap1)
                .HasForeignKey(d => d.Itm_CM_ITEM);

        }
    }
}
